﻿#ifndef __HTTP_HANDLES_H__
#define __HTTP_HANDLES_H__

#include "../iocp/IOCP/fileio.h"
#include "../utils/NetHttp/httpserver.h"
#include "../utils/jsoncpp/value.h"
#include "../utils/jsoncpp/reader.h"
#include "sqldata.h"
#define LOG  printf

class CHttpHandles
{
public:
    CHttpHandles();
    ~CHttpHandles();

    static void __stdcall ErrorHandle(PHTTPINFO pHttpInfo);
public:
    static void __stdcall General(PHTTPINFO pHttpInfo);

    static void __stdcall HeartBeat(PHTTPINFO pHttpInfo);
    static void __stdcall Login(PHTTPINFO pHttpInfo);
    static void __stdcall Logout(PHTTPINFO pHttpInfo);
    static void __stdcall GetPermissions(PHTTPINFO pHttpInfo);

private:
    static bool TakeRequest(PHTTPINFO pHttpInfo, Json::Value& request);
    static bool TakePermissions(const std::string& access, Json::Value& root);
    static bool TakeUserInfo(const std::string& access, const std::string& password, Json::Value& root);
    static bool Response(PHTTPINFO pHttpInfo, const Json::Value& response);
    static bool RequestError(PHTTPINFO pHttpInfo, const std::string& message);
private:
    static std::map<std::string, std::string> gTokens;
    static CSqlData gSqlData;
};


#endif
